-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flag to allow more flexible variable redefinition #18727
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
Most likely this is because this PR somehow breaks logic for overrides with custom properties (i.e. those where setter has different type). |
That makes sense. And to be fair, it's a rather sneaky thing that I'm doing there, so I suppose you could consider it as a stress-test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally had time to look at this. I think the approach looks very promising. I left a bunch of comments but they are minor. As it was proposed before I suggest again to run against mypy_primer
with the flag set to True
to get better idea of impact.
@@ -226,12 +233,15 @@ def update_from_options(self, frames: list[Frame]) -> bool: | |||
for key in keys: | |||
current_value = self._get(key) | |||
resulting_values = [f.types.get(key, current_value) for f in frames] | |||
if any(x is None for x in resulting_values): | |||
old_semantics = not self.bind_all or extract_var_from_literal_hash(key) is None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite tricky and with time we may forget what old_semantics
mean. I think it is worth adding a comment with motivating code example here.
@@ -316,6 +316,8 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface): | |||
# Vars for which partial type errors are already reported | |||
# (to avoid logically duplicate errors with different error context). | |||
partial_reported: set[Var] | |||
# Short names of Var nodes whose previous inferred type has been widened via assignment | |||
widened_vars: list[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this is only used to track updates in a loop. If so, can this be replaced with a counter, or even a boolean flag? Otherwise people may accidentally start using this for something else, and short names are fragile w.r.t. name clashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are to simplify debugging. Added a note about this.
if ( | ||
(partials_new == partials_old) | ||
and (not self.binder.last_pop_changed or iter > 3) | ||
and (widened_new == widened_old or iter > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FMI, why these numbers (1 vs 3) are different? They look quite arbitrary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are quite arbitrary, but these numbers hopefully don't slow things down too much while supporting almost all valid use cases. I'll add a comment to elaborate on this a bit. We might need to tweak the limits in the future, but these seem to work okay so far.
if v.type is not None: | ||
n = NameExpr(v.name) | ||
n.node = v | ||
self.binder.assign_type(n, v.type, v.type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to use .put()
here? Or is the TODO above about this? (If yes, it is not obvious there)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if put
will work, but it might. I will update the TODO.
@@ -3286,7 +3317,10 @@ def check_assignment( | |||
lvalue_type = make_optional_type(lvalue_type) | |||
self.set_inferred_type(lvalue.node, lvalue, lvalue_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this is old special-casing for inferring optional types from assignments in if statements. Shouldn't we make this conditional on new redefinition flag being False
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it seems that we can disable this logic when using the new redefinition flag.
new_type = DeletedType(source=source) | ||
var.node.type = new_type | ||
if self.options.allow_redefinition_new: | ||
self.binder.assign_type(var, new_type, new_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I fully understand the logic here. But again, it seems .put()
may be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear. I will add a TODO comment and investigate it later.
test-data/unit/check-redefine2.test
Outdated
reveal_type(C4().x) # N: Revealed type is "builtins.list[builtins.str]" | ||
[builtins fixtures/list.pyi] | ||
|
||
[case testZZZ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this test is doing here (also it doesn't set new flag).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was some leftovers from debugging. I will remove it.
test-data/unit/check-redefine2.test
Outdated
except Exception: | ||
# TODO: Too wide | ||
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]" | ||
# TODO: Too wide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this problem specific to try/except? If yes, it is fine to leave it for a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the types are probably the best we can reasonably infer. I'll remove the comment (and update the test case slightly).
reveal_type(x) # N: Revealed type is "builtins.int" | ||
else: | ||
x = '' | ||
reveal_type(x) # N: Revealed type is "builtins.str" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe my missed them, but I think it is important to add tests with deeper (like 2-level and maybe even 3-level) nesting of if
statements, checking the revealed type on exiting each nesting level.
mypy/checker.py
Outdated
self.widened_vars.append(inferred.name) | ||
self.set_inferred_type(inferred, lvalue, lvalue_type) | ||
self.binder.put(lvalue, rvalue_type) | ||
# TODO: hack, maybe integrate into put? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I am not sure why integrating the update of declaration into .put()
would be better.
This crash seems to be unrelated to this PR: #18764 |
I fixed issues related to the three examples mentioned above by @cdce8p and @A5rocks. It took me a while since I've been traveling.
I didn't change this to silently infer |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This lets us see the impact on mypy primer.
Temporarily enabled |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: paroxython (https://github.com/laowantong/paroxython)
- paroxython/derived_labels_db.py:189: error: Invalid index type "str | Any" for "dict[LabelName, dict[Span, Any]]"; expected type "LabelName" [index]
+ paroxython/derived_labels_db.py:189: error: Invalid index type "Any | str" for "dict[LabelName, dict[Span, Any]]"; expected type "LabelName" [index]
+ paroxython/recommend_programs.py:263: error: Argument 1 to "cost_bucket" has incompatible type "float"; expected "int" [arg-type]
beartype (https://github.com/beartype/beartype)
+ beartype/_util/utilobjattr.py:138: error: Need type annotation for "attrs_name_to_value_explicit" [var-annotated]
+ beartype/door/_func/infer/collection/infercollectionitems.py:464: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_check/forward/reference/fwdrefmake.py:195: error: "type" has no attribute "__name_beartype__" [attr-defined]
+ beartype/_check/forward/reference/fwdrefmake.py:196: error: "type" has no attribute "__scope_name_beartype__" [attr-defined]
+ beartype/_decor/_nontype/decornontype.py:208: error: Unused "type: ignore" comment [unused-ignore]
vision (https://github.com/pytorch/vision)
+ torchvision/models/_api.py:192: error: Need type annotation for "BUILTIN_MODELS" (hint: "BUILTIN_MODELS: dict[<type>, <type>] = ...") [var-annotated]
+ torchvision/datasets/cityscapes.py:195: error: Unused "type: ignore" comment [unused-ignore]
+ torchvision/datasets/_stereo_matching.py:127: error: Too many arguments for "__call__" of "StandardTransform" [call-arg]
+ torchvision/datasets/_stereo_matching.py:127: error: Need more than 2 values to unpack (3 expected) [misc]
+ torchvision/datasets/_optical_flow.py:69: error: Too many arguments for "__call__" of "StandardTransform" [call-arg]
+ torchvision/datasets/_optical_flow.py:69: error: Need more than 2 values to unpack (4 expected) [misc]
dragonchain (https://github.com/dragonchain/dragonchain)
+ dragonchain/lib/keys.py:70:20: error: Incompatible types in assignment (expression has type "DCKeys", variable has type "None") [assignment]
+ dragonchain/lib/keys.py:73:12: error: Incompatible return value type (got "None", expected "DCKeys") [return-value]
+ dragonchain/lib/database/redisearch.py:115:29: error: Incompatible types in assignment (expression has type "Redis[Any]", variable has type "None") [assignment]
speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)
- backend/services/user_updater_helpers.py:190: error: Incompatible types in assignment (expression has type "list[list[Run]]", variable has type "list[Run]") [assignment]
- backend/services/user_updater_helpers.py:191: error: Argument 1 to "append" of "list" has incompatible type "list[Run]"; expected "Run" [arg-type]
- backend/services/user_updater_helpers.py:192: error: Incompatible types in assignment (expression has type "list[Run]", target has type "list[list[Run]]") [assignment]
- backend/services/user_updater_helpers.py:196: error: Incompatible types in assignment (expression has type "list[list[Run]]", variable has type "list[Run]") [assignment]
- backend/services/user_updater_helpers.py:199: error: Value of type "Run" is not indexable [index]
- backend/services/user_updater_helpers.py:203: error: Argument 2 to "insert" of "list" has incompatible type "list[Run]"; expected "Run" [arg-type]
- backend/services/user_updater_helpers.py:205: error: Argument 1 to "append" of "list" has incompatible type "list[Run]"; expected "Run" [arg-type]
- backend/services/user_updater_helpers.py:225: error: Incompatible types in assignment (expression has type "float", variable has type "int") [assignment]
- backend/api/api_wrappers.py:70: error: Dict entry 0 has incompatible type "str": "dict[str, str]"; expected "str": "str" [dict-item]
- backend/api/tournament_scheduler_api.py:317: error: Incompatible types in assignment (expression has type "str | int | float | bool | dict[str, Any] | list[Any] | None", variable has type "list[Any]") [assignment]
schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/jsonld_context.py: note: In function "makerdf":
+ schema_salad/jsonld_context.py:234:34: error: Argument 1 to "urldefrag" has incompatible type "Any | Iterable[str]"; expected "str" [arg-type]
trio (https://github.com/python-trio/trio)
- src/trio/_socket.py:240: error: Argument 1 to "getaddrinfo" of "HostnameResolver" has incompatible type "bytes | str | None"; expected "bytes | None" [arg-type]
+ src/trio/_socket.py:240: error: Argument 1 to "getaddrinfo" of "HostnameResolver" has incompatible type "bytes | Any | str | None"; expected "bytes | None" [arg-type]
+ src/trio/_core/_run.py:1889: error: Unused "type: ignore" comment [unused-ignore]
+ src/trio/_core/_run.py:1889: error: Item "Coroutine[object, Never, object]" of "Coroutine[object, Never, object] | Coroutine[Any, Any, object]" has no attribute "cr_frame" [union-attr]
+ src/trio/_core/_run.py:1889: note: Error code "union-attr" not covered by "type: ignore" comment
+ src/trio/_core/_run.py:1889: error: Item "Coroutine[Any, Any, object]" of "Coroutine[object, Never, object] | Coroutine[Any, Any, object]" has no attribute "cr_frame" [union-attr]
+ src/trio/testing/_fake_net.py:291: error: Cannot determine type of "_" [has-type]
+ src/trio/_core/_tests/test_run.py:2785: error: Item "BaseException" of "Any | BaseException" has no attribute "message" [union-attr]
+ src/trio/_core/_tests/test_run.py:2786: error: Item "BaseException" of "Any | BaseException" has no attribute "exceptions" [union-attr]
+ src/trio/_core/_tests/test_ki.py:166: error: "None" not callable [misc]
+ src/trio/_core/_tests/test_ki.py:171: error: "None" not callable [misc]
+ src/trio/_core/_tests/test_ki.py:175: error: "None" not callable [misc]
+ src/trio/_core/_tests/test_ki.py:180: error: "None" not callable [misc]
+ src/trio/_core/_tests/test_ki.py:190: error: "None" not callable [misc]
+ src/trio/_core/_tests/test_ki.py:199: error: "None" not callable [misc]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/builder.py: note: In member "generate_arg" of class "Builder":
+ cwltool/builder.py:641:72: error: Redundant cast to "list[str]" [redundant-cast]
- cwltool/pack.py:35:22: error: Argument 1 to "find_run" has incompatible type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected "CWLObjectType | int | float | str | CommentedMap | CommentedSeq | None" [arg-type]
+ cwltool/pack.py:35:22: error: Argument 1 to "find_run" has incompatible type "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected "CWLObjectType | int | float | str | CommentedMap | CommentedSeq | None" [arg-type]
+ cwltool/pack.py: note: In function "pack":
+ cwltool/pack.py:233:13: error: Argument 1 to "update" has incompatible type "MutableMapping[Any, Any]"; expected "CommentedSeq | CommentedMap" [arg-type]
+ cwltool/command_line_tool.py: note: In member "make_job_runner" of class "CommandLineTool":
+ cwltool/command_line_tool.py:421:46: error: Argument 2 to "insert" of "list" has incompatible type "dict[str, str]"; expected "CWLObjectType" [arg-type]
+ cwltool/command_line_tool.py:424:53: error: Argument 2 to "insert" of "list" has incompatible type "dict[str, str]"; expected "CWLObjectType" [arg-type]
- cwltool/main.py:377:41: error: Unsupported right operand type for in ("Any | int | float | str | CommentedMap | CommentedSeq") [operator]
+ cwltool/main.py:377:41: error: Unsupported right operand type for in ("int | float | str | CommentedMap | CommentedSeq") [operator]
- cwltool/main.py:379:49: error: Argument 1 to "resolve_overrides" has incompatible type "Any | int | float | str | CommentedMap | CommentedSeq"; expected "CommentedMap | CommentedSeq | str | None" [arg-type]
+ cwltool/main.py:379:49: error: Argument 1 to "resolve_overrides" has incompatible type "int | float | str | CommentedMap | CommentedSeq"; expected "CommentedMap | CommentedSeq | str | None" [arg-type]
- cwltool/main.py:380:9: error: Item "int" of "Any | int | float | str | CommentedMap | CommentedSeq" has no attribute "__delitem__" [union-attr]
+ cwltool/main.py:380:9: error: Item "int" of "int | float | str | CommentedMap | CommentedSeq" has no attribute "__delitem__" [union-attr]
- cwltool/main.py:380:9: error: Item "float" of "Any | int | float | str | CommentedMap | CommentedSeq" has no attribute "__delitem__" [union-attr]
+ cwltool/main.py:380:9: error: Item "float" of "int | float | str | CommentedMap | CommentedSeq" has no attribute "__delitem__" [union-attr]
- cwltool/main.py:380:9: error: Item "str" of "Any | int | float | str | CommentedMap | CommentedSeq" has no attribute "__delitem__" [union-attr]
+ cwltool/main.py:380:9: error: Item "str" of "int | float | str | CommentedMap | CommentedSeq" has no attribute "__delitem__" [union-attr]
optuna (https://github.com/optuna/optuna)
+ optuna/study/_dataframe.py:99: error: Item "type" of "Any | type[object]" has no attribute "DataFrame" [union-attr]
+ optuna/study/_dataframe.py:106: error: Item "type" of "Any | type[object]" has no attribute "DataFrame" [union-attr]
+ optuna/study/_dataframe.py:106: error: Item "type" of "Any | type[object]" has no attribute "MultiIndex" [union-attr]
+ tests/test_cli.py:1218: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1218: note: Possible overload variants:
+ tests/test_cli.py:1218: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1218: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1219: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1219: note: Possible overload variants:
+ tests/test_cli.py:1219: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1219: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1220: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1220: note: Possible overload variants:
+ tests/test_cli.py:1220: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1220: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1274: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1274: note: Possible overload variants:
+ tests/test_cli.py:1274: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1274: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1275: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1275: note: Possible overload variants:
+ tests/test_cli.py:1275: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1275: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1276: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1276: note: Possible overload variants:
+ tests/test_cli.py:1276: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1276: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1314: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1314: note: Possible overload variants:
+ tests/test_cli.py:1314: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1314: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1315: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1315: note: Possible overload variants:
+ tests/test_cli.py:1315: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1315: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/test_cli.py:1352: error: No overload variant of "__getitem__" of "list" matches argument type "str" [call-overload]
+ tests/test_cli.py:1352: note: Possible overload variants:
+ tests/test_cli.py:1352: note: def __getitem__(self, SupportsIndex, /) -> dict[str, str]
+ tests/test_cli.py:1352: note: def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[str, str]]
+ tests/samplers_tests/test_grid.py:56: error: Unused "type: ignore" comment [unused-ignore]
+ optuna/visualization/_parallel_coordinate.py:217: error: Invalid index type "Any | float" for "defaultdict[int | str, int]"; expected type "int | str" [index]
+ optuna/visualization/_parallel_coordinate.py:217: error: Invalid index type "float | int | Any" for "defaultdict[int | str, int]"; expected type "int | str" [index]
+ optuna/visualization/_parallel_coordinate.py:221: error: Invalid index type "Any | float | int" for "defaultdict[int | str, int]"; expected type "int | str" [index]
httpx-caching (https://github.com/johtso/httpx-caching)
+ httpx_caching/_policy.py:475: error: Unused "type: ignore" comment [unused-ignore]
- httpx_caching/_policy.py:491: error: Incompatible types in assignment (expression has type "None", target has type "int") [assignment]
+ httpx_caching/_policy.py:494: error: Incompatible types in assignment (expression has type "int", target has type "None") [assignment]
alerta (https://github.com/alerta/alerta)
- alerta/models/alert.py:664: error: Incompatible types in assignment (expression has type "str", variable has type "ChangeType") [assignment]
+ alerta/plugins/escalate.py:11: error: Need type annotation for "escalate_map" (hint: "escalate_map: dict[<type>, <type>] = ...") [var-annotated]
bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch/mirror.py: note: In member "synchronize" of class "Mirror":
+ src/bandersnatch/mirror.py:58: error: Incompatible types in assignment (expression has type "datetime", variable has type "None") [assignment]
+ src/bandersnatch/mirror.py: note: In member "wrapup_successful_sync" of class "BandersnatchMirror":
+ src/bandersnatch/mirror.py:478: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/test_configuration.py: note: In member "setUp" of class "TestBandersnatchConf":
+ src/bandersnatch/tests/test_configuration.py:28: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/test_configuration.py:29: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/test_configuration.py:30: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/test_configuration.py: note: In member "tearDown" of class "TestBandersnatchConf":
+ src/bandersnatch/tests/test_configuration.py:37: error: Statement is unreachable [unreachable]
+ src/bandersnatch_filter_plugins/metadata_filter.py:109: error: Unused "type: ignore" comment [unused-ignore]
+ src/bandersnatch_filter_plugins/metadata_filter.py:110: error: Unused "type: ignore" comment [unused-ignore]
+ src/bandersnatch/tests/test_filter.py: note: In member "setUp" of class "TestBandersnatchFilter":
+ src/bandersnatch/tests/test_filter.py:31: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/test_filter.py:32: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/test_filter.py:33: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/test_filter.py:34: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/test_filter.py: note: In member "tearDown" of class "TestBandersnatchFilter":
+ src/bandersnatch/tests/test_filter.py:39: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "setUp" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:387: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:388: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:392: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "setUp_dirs" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:399: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "setUp_backEnd" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:414: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "setUp_mirror" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:431: error: Cannot determine type of "mirror_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "setUp_mirrorDirs" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:453: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "setUp_Structure" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:555: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:557: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "tearDown" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:572: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_hash_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:659: error: Cannot determine type of "sample_file" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_rewrite" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:698: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_update_safe" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:708: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_compare_files" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:718: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:719: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:720: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_find" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:744: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_open_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:754: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:769: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_write_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:778: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_read_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:791: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:808: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_delete" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:815: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:818: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_delete_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:830: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_copy_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:841: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_mkdir" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:853: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:856: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:860: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_scandir" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:864: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_rmdir" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:888: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:892: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:896: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:900: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_is_dir" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:906: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:911: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:916: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_is_file" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:921: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_symlink" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:930: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_get_hash" of class "BaseStoragePluginTestCase":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:939: error: Cannot determine type of "sample_file" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_mkdir" of class "TestSwiftStoragePlugin":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:986: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:991: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_rmdir" of class "TestSwiftStoragePlugin":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:999: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:1004: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:1010: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py: note: In member "test_copy_file" of class "TestSwiftStoragePlugin":
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:1016: error: Cannot determine type of "mirror_base_path" [has-type]
+ src/bandersnatch/tests/plugins/test_storage_plugins.py:1018: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_regex_name.py: note: In member "setUp" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_regex_name.py:24: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_regex_name.py:25: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_regex_name.py:26: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_regex_name.py: note: In member "tearDown" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_regex_name.py:30: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_prerelease_name.py: note: In member "setUp" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_prerelease_name.py:24: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_prerelease_name.py:25: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_prerelease_name.py:26: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_prerelease_name.py: note: In member "tearDown" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_prerelease_name.py:30: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_latest_release.py: note: In member "setUp" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_latest_release.py:23: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_latest_release.py:24: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_latest_release.py:25: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_latest_release.py: note: In member "tearDown" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_latest_release.py:29: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_filename.py: note: In member "setUp" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_filename.py:23: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_filename.py:24: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_filename.py:25: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_filename.py: note: In member "tearDown" of class "BasePluginTestCase":
+ src/bandersnatch/tests/plugins/test_filename.py:29: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py: note: In member "setUp" of class "TestBlockListProject":
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:26: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:27: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:28: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py: note: In member "tearDown" of class "TestBlockListProject":
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:32: error: Statement is unreachable [unreachable]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py: note: In member "setUp" of class "TestBlockListRelease":
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:171: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:172: error: Incompatible types in assignment (expression has type "TemporaryDirectory[str]", variable has type "None") [assignment]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:173: error: "None" has no attribute "name" [attr-defined]
+ src/bandersnatch/tests/plugins/test_blocklist_name.py: note: In member "tearDown" of class "TestBlockListRelease":
+ src/bandersnatch/tests/plugins/test_blocklist_name.py:177: error: Statement is unreachable [unreachable]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/_git.py:17: error: Incompatible types in assignment (expression has type "str", variable has type "bytes") [assignment]
- src/prefect/utilities/_git.py:21: error: Incompatible return value type (got "bytes", expected "Optional[str]") [return-value]
- src/prefect/utilities/_git.py:30: error: Incompatible types in assignment (expression has type "str", variable has type "bytes") [assignment]
- src/prefect/utilities/_git.py:34: error: Incompatible return value type (got "bytes", expected "Optional[str]") [return-value]
- src/prefect/_internal/concurrency/inspection.py:80: error: Incompatible types in assignment (expression has type "Optional[FrameType]", variable has type "FrameType") [assignment]
- src/prefect/utilities/collections.py:398: error: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[Any, dict[str, VT?]], Any]") [assignment]
- src/prefect/utilities/collections.py:412: error: Too few arguments [call-arg]
- src/prefect/utilities/collections.py:487: error: "None" object is not iterable [misc]
- src/prefect/utilities/collections.py:492: error: Argument 1 to "dict" has incompatible type "list[Optional[Any]]"; expected "Iterable[tuple[Any, Any]]" [arg-type]
- src/prefect/utilities/collections.py:652: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
- src/prefect/settings/sources.py:156: error: Incompatible types in assignment (expression has type "Union[str, Any, None]", variable has type "str") [assignment]
- src/prefect/_vendor/croniter/croniter.py:80: error: Incompatible types in assignment (expression has type "_UTCclass", variable has type "timezone") [assignment]
+ src/prefect/locking/memory.py:37: error: Incompatible types in assignment (expression has type "Self", variable has type "None") [assignment]
+ src/prefect/locking/memory.py:38: error: Incompatible return value type (got "None", expected "Self") [return-value]
- src/prefect/server/utilities/database.py:414: error: Incompatible types in assignment (expression has type "tuple[Any, Any]", variable has type "tuple[Any]") [assignment]
- src/prefect/client/utilities.py:96: error: Incompatible types in assignment (expression has type "AbstractAsyncContextManager[R?, None]", variable has type "PrefectClient") [assignment]
- src/prefect/logging/loggers.py:152: error: Incompatible types in assignment (expression has type "Logger", variable has type "LoggerAdapter[Logger]") [assignment]
- src/prefect/logging/loggers.py:153: error: "LoggerAdapter[Logger]" has no attribute "disabled" [attr-defined]
- src/prefect/_internal/concurrency/cancellation.py:583: error: Incompatible types in assignment (expression has type "WatcherThreadCancelScope", variable has type "AlarmCancelScope") [assignment]
- src/prefect/utilities/callables.py:503: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/utilities/callables.py:505: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/utilities/callables.py:526: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/utilities/callables.py:528: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/utilities/callables.py:561: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/utilities/callables.py:563: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/utilities/callables.py:571: error: Incompatible types in assignment (expression has type "list[None]", variable has type "list[Optional[expr]]") [assignment]
- src/prefect/utilities/callables.py:571: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
- src/prefect/utilities/callables.py:571: note: Consider using "Sequence" instead, which is covariant
- src/prefect/utilities/callables.py:573: error: Unsupported operand types for + ("list[None]" and "list[Optional[expr]]") [operator]
- src/prefect/utilities/callables.py:608: error: Incompatible types in assignment (expression has type "type[_empty]", variable has type "Optional[expr]") [assignment]
- src/prefect/_internal/concurrency/services.py:145: error: Incompatible types in assignment (expression has type "float", variable has type "int") [assignment]
- src/prefect/settings/legacy.py:65: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "Settings") [assignment]
+ src/prefect/settings/legacy.py:105: note: Expected:
+ src/prefect/settings/legacy.py:105: note: def __hash__() -> int
+ src/prefect/settings/legacy.py:105: note: Got:
+ src/prefect/settings/legacy.py:105: note: def __hash__(self: object) -> int
+ src/prefect/settings/legacy.py:136: note: Expected:
+ src/prefect/settings/legacy.py:136: note: def __hash__() -> int
+ src/prefect/settings/legacy.py:136: note: Got:
+ src/prefect/settings/legacy.py:136: note: def __hash__(self: object) -> int
+ src/prefect/settings/legacy.py:136: note: Expected:
+ src/prefect/settings/legacy.py:136: note: def __hash__() -> int
+ src/prefect/settings/legacy.py:136: note: Got:
+ src/prefect/settings/legacy.py:136: note: def __hash__(self: object) -> int
- src/prefect/states.py:271: error: Incompatible types in assignment (expression has type "BaseException", variable has type "ResultRecord[Any]") [assignment]
- src/prefect/states.py:313: error: Incompatible types in assignment (expression has type "BaseException", variable has type "ResultRecord[Any]") [assignment]
- src/prefect/states.py:448: error: Incompatible types in assignment (expression has type "R", variable has type "list[Any]") [assignment]
- src/prefect/states.py:503: error: Incompatible types in assignment (expression has type "type[CrashedRun]", variable has type "type[FailedRun]") [assignment]
- src/prefect/states.py:506: error: Incompatible types in assignment (expression has type "type[CancelledRun]", variable has type "type[FailedRun]") [assignment]
- src/prefect/client/base.py:127: error: Incompatible types in assignment (expression has type "Union[tuple[type[BaseException], BaseException, TracebackType], tuple[None, None, None]]", variable has type "tuple[None, None, None]") [assignment]
+ src/prefect/server/events/jinja_filters.py:59: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/futures.py:540: error: Incompatible types in assignment (expression has type "list[PrefectFuture[R]]", variable has type "set[PrefectFuture[R]]") [assignment]
- src/prefect/filesystems.py:363: error: Incompatible types in assignment (expression has type "Path", variable has type "TextIOWrapper[_WrappedBuffer]") [assignment]
- src/prefect/filesystems.py:364: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "relative_to" [attr-defined]
- src/prefect/filesystems.py:373: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "is_dir" [attr-defined]
- src/prefect/filesystems.py:376: error: "TextIOWrapper[_WrappedBuffer]" has no attribute "as_posix" [attr-defined]
- src/prefect/flows.py:2367: error: Incompatible types in assignment (expression has type "BaseException", variable has type "StepExecutionError") [assignment]
- src/prefect/flows.py:2512: error: Incompatible types in assignment (expression has type "Optional[expr]", variable has type "expr") [assignment]
- src/prefect/deployments/runner.py:535: error: Incompatible types in assignment (expression has type "list[Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]]", variable has type "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]") [assignment]
- src/prefect/deployments/runner.py:540: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, Union[str, Any, int, float, timedelta, datetime, None]]"; expected "Union[int, float, timedelta, None]" [arg-type]
+ src/prefect/deployments/runner.py:540: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, Union[Any, Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, datetime, None]]"; expected "Union[int, float, timedelta, None]" [arg-type]
- src/prefect/deployments/runner.py:540: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, Union[str, Any, int, float, timedelta, datetime, None]]"; expected "Union[datetime, str, None]" [arg-type]
+ src/prefect/deployments/runner.py:540: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, Union[Any, Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, datetime, None]]"; expected "Union[datetime, str, None]" [arg-type]
- src/prefect/deployments/runner.py:540: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, Union[str, Any, int, float, timedelta, datetime, None]]"; expected "Optional[str]" [arg-type]
+ src/prefect/deployments/runner.py:540: error: Argument 1 to "construct_schedule" has incompatible type "**dict[str, Union[Any, Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, datetime, None]]"; expected "Optional[str]" [arg-type]
- src/prefect/deployments/runner.py:547: error: Item "None" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]" has no attribute "__iter__" (not iterable) [union-attr]
+ src/prefect/deployments/runner.py:547: error: Item "None" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, list[Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]], None]" has no attribute "__iter__" (not iterable) [union-attr]
- src/prefect/deployments/runner.py:547: error: Item "int" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]" has no attribute "__iter__" (not iterable) [union-attr]
+ src/prefect/deployments/runner.py:547: error: Item "int" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, list[Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]], None]" has no attribute "__iter__" (not iterable) [union-attr]
- src/prefect/deployments/runner.py:547: error: Item "float" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]" has no attribute "__iter__" (not iterable) [union-attr]
+ src/prefect/deployments/runner.py:547: error: Item "float" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, list[Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]], None]" has no attribute "__iter__" (not iterable) [union-attr]
- src/prefect/deployments/runner.py:547: error: Item "timedelta" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]" has no attribute "__iter__" (not iterable) [union-attr]
+ src/prefect/deployments/runner.py:547: error: Item "timedelta" of "Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, list[Union[Iterable[str], Iterable[Union[int, float, timedelta]], int, float, timedelta, None]], None]" has no attribute "__iter__" (not iterable) [union-attr]
- src/prefect/cache_policies.py:274: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
- src/prefect/tasks.py:180: error: Incompatible types in assignment (expression has type "Optional[State[Any]]", variable has type "State[Any]") [assignment]
- src/prefect/tasks.py:773: error: Incompatible types in assignment (expression has type "Union[int, str]", variable has type "str") [assignment]
- src/prefect/tasks.py:874: error: Incompatible types in assignment (expression has type "Union[int, str]", variable has type "str") [assignment]
+ src/prefect/tasks.py:877: error: Value of type "Union[str, int]" is not indexable [index]
- src/prefect/tasks.py:1412: error: Incompatible types in assignment (expression has type "PrefectFutureList[Any]", variable has type "list[PrefectDistributedFuture[R]]") [assignment]
- src/prefect/tasks.py:1427: error: Incompatible return value type (got "list[PrefectDistributedFuture[R]]", expected "Union[list[State[R]], PrefectFutureList[R]]") [return-value]
+ src/prefect/tasks.py:1427: error: Incompatible return value type (got "Union[list[PrefectDistributedFuture[R]], PrefectFutureList[Any]]", expected "Union[list[State[R]], PrefectFutureList[R]]") [return-value]
+ src/prefect/flow_engine.py:138: error: Need type annotation for "flow" [var-annotated]
+ src/prefect/flow_engine.py:358: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/flow_engine.py:363: error: Incompatible return value type (got "Union[R, type[NotSet]]", expected "Union[R, State[Any], None]") [return-value]
+ src/prefect/flow_engine.py:363: error: Incompatible return value type (got "Union[Any, Exception]", expected "Union[R, State[Any], None]") [return-value]
- src/prefect/flow_engine.py:913: error: Incompatible return value type (got "Union[R, type[NotSet]]", expected "Union[R, State[Any], None]") [return-value]
+ src/prefect/flow_engine.py:913: error: Incompatible return value type (got "Union[R, type[NotSet], Any]", expected "Union[R, State[Any], None]") [return-value]
+ src/prefect/flow_engine.py:925: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/flow_engine.py:930: error: Incompatible return value type (got "Union[R, type[NotSet]]", expected "Union[R, State[Any], None]") [return-value]
+ src/prefect/flow_engine.py:930: error: Incompatible return value type (got "Union[Any, Exception]", expected "Union[R, State[Any], None]") [return-value]
- src/prefect/task_engine.py:1362: error: Argument 1 to "handle_success" of "AsyncTaskRunEngine" has incompatible type "Optional[ResultRecord[Any]]"; expected "R" [arg-type]
+ src/prefect/task_engine.py:1362: error: Argument 1 to "handle_success" of "AsyncTaskRunEngine" has incompatible type "Union[ResultRecord[Any], Any, None]"; expected "R" [arg-type]
- src/prefect/task_engine.py:1363: error: Incompatible return value type (got "Optional[ResultRecord[Any]]", expected "Union[R, Coroutine[Any, Any, R]]") [return-value]
+ src/prefect/task_engine.py:1363: error: Incompatible return value type (got "Union[ResultRecord[Any], Any, None]", expected "Union[R, Coroutine[Any, Any, R]]") [return-value]
- src/prefect/server/orchestration/core_policy.py:774: error: Incompatible types in assignment (expression has type "float", variable has type "Union[int, list[int], None]") [assignment]
- src/prefect/server/models/task_runs.py:502: error: R? has no attribute "__await__" [attr-defined]
- src/prefect/server/models/task_runs.py:502: error: Missing positional argument "db" in call to "validate_proposed_state" of "TaskOrchestrationContext" [call-arg]
- src/prefect/server/models/flow_runs.py:580: error: R? has no attribute "__await__" [attr-defined]
- src/prefect/server/models/flow_runs.py:580: error: Missing positional argument "db" in call to "validate_proposed_state" of "FlowOrchestrationContext" [call-arg]
+ src/prefect/server/services/cancellation_cleanup.py:191: error: Need type annotation for "state" [var-annotated]
- src/prefect/server/api/events.py:145: error: Incompatible types in assignment (expression has type "Optional[ReceivedEvent]", variable has type "ReceivedEvent") [assignment]
- src/prefect/server/api/server.py:234: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "str") [assignment]
- src/prefect/server/api/server.py:235: error: "str" has no attribute "read" [attr-defined]
- src/prefect/server/api/server.py:239: error: Incompatible types in assignment (expression has type "TextIOWrapper[_WrappedBuffer]", variable has type "str") [assignment]
- src/prefect/server/api/server.py:240: error: "str" has no attribute "write" [attr-defined]
... (truncated 54 lines) ...
pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/page.py:1229: error: Incompatible types in assignment (expression has type "Any | dict[str, Any]", target has type "str") [assignment]
+ pyppeteer/network_manager.py:707: error: Need type annotation for "_hash" [var-annotated]
+ pyppeteer/network_manager.py:727: error: Unsupported target for indexed assignment ("dict[Any, Any] | Any | str | None") [index]
+ pyppeteer/frame_manager.py:174: error: Argument 1 to "get" of "dict" has incompatible type "Any | None"; expected "str" [arg-type]
+ pyppeteer/chromium_downloader.py:36: error: Unused "type: ignore" comment [unused-ignore]
- pyppeteer/__init__.py:16: error: Incompatible types in assignment (expression has type "None", variable has type "str") [assignment]
- pyppeteer/__init__.py:27: error: Incompatible types in assignment (expression has type "str", variable has type "Callable[[str], str]") [assignment]
+ pyppeteer/__init__.py:27: error: Incompatible types in assignment (expression has type "str | None", variable has type "Callable[[str], str]") [assignment]
altair (https://github.com/vega/altair)
+ altair/utils/schemapi.py:982: error: Incompatible types in assignment (expression has type "Self", variable has type "None") [assignment]
+ altair/utils/schemapi.py:983: error: Incompatible return value type (got "None", expected "Self") [return-value]
+ tools/schemapi/schemapi.py:980: error: Incompatible types in assignment (expression has type "Self", variable has type "None") [assignment]
+ tools/schemapi/schemapi.py:981: error: Incompatible return value type (got "None", expected "Self") [return-value]
comtypes (https://github.com/enthought/comtypes)
- comtypes/tools/codegenerator/namespaces.py:126: error: Incompatible types in assignment (expression has type "set[str] | None", variable has type "str | None") [assignment]
- comtypes/_memberspec.py:100: error: Argument 1 to "append" of "list" has incompatible type "tuple[int, str | None, Any]"; expected "tuple[int, str | None]" [arg-type]
+ comtypes/_memberspec.py:100: error: Argument 1 to "append" of "list" has incompatible type "tuple[int, str | None, Any | _Pointer[tagVARIANT] | _SimpleCData[Any] | _Pointer[Any] | CFuncPtr | _ctypes.Union | Structure | Array[Any]]"; expected "tuple[int, str | None]" [arg-type]
- comtypes/_memberspec.py:392: error: Incompatible types in assignment (expression has type "Callable[..., Any] | None", variable has type "Callable[[Any, VarArg(Any)], Any]") [assignment]
- comtypes/_memberspec.py:425: error: Incompatible types in assignment (expression has type "named_property", variable has type "property") [assignment]
... (truncated 1895 lines) ...``` |
There are still some false positives in the mypy_primer output that I want to fix before merging, but I won't attempt to fix every single issue in this PR, since the new behavior is behind a flag. |
Sure, there is no point in turning this into a mega-PR. Let me know if/when you want me to review this PR again. |
Btw if you want a clean mypy_primer diff on the local partial types front, you can try something like:
|
Infer union types for simple variables from multiple assignments, if the variable isn't annotated. The feature is enabled via
--allow-redefinition-new
.--local-partial-types
must also be enabled.This is still experimental and has known issues, so it's not documented anywhere. It works well enough that it can be used for non-trivial experimentation, however.
Closes #6233. Closes #6232. Closes #18568. Fixes #18619.
In this example, the type of
x
is inferred asint | str
when using the new behavior:Here is a summary of how it works:
None
values are no longer special, and we don't use partial None if the feature is enabled for simple variables.self.x
) continue to work as in the past. Attribute types can't be widened, since they are externally visible and widening could cause confusion, but this is something we might relax in the future. Globals can be widened, however. This seems necessary for consistency.x = 0
outside loop andx = [x]
within the loop body).There are some other known bugs and limitations:
nonlocal
and some other features. We don't have good test coverage for deferrals, mypy daemon, and disabling strict optional.In self check the feature generates 6 additional errors, which all seem correct -- we infer more precise types, which will generate additional errors due to invariant containers and fixing false negatives.
When type checking the largest internal codebase at Dropbox, this generated about 700 new errors, the vast majority of which seemed legitimate. Mostly they were due to inferring more precise types for variables that used to have
Any
types. I used a recent but not the latest version of the feature to type check the internal codebase.